package com.common.emums;

import com.common.ErrorCodeEnum;
import com.common.exception.BusinessException;

/**
 * @Author: zql
 * @Description: 数据权限类型
 * @Data: 14:34 2021/5/11
 */
public enum DataScopeType {
    //枚举值
    DATA_SCOPE_ALL((byte) 0, "全部数据权限"),
    DATA_SCOPE_CUSTOM((byte) 1, "自定数据权限"),
    DATA_SCOPE_DEPT((byte) 2, "部门数据权限"),
    DATA_SCOPE_DEPT_AND_CHILD((byte) 3, "部门及以下数据权限"),
    DATA_SCOPE_SELF((byte) 4, "仅本人数据权限");

    private final Byte code;
    private final String info;

    DataScopeType(Byte code, String info) {
        this.code = code;
        this.info = info;
    }

    public boolean equals(Byte code){
       return this.code.equals(code);
    }

    public static String getInfo(Byte code){
        for (DataScopeType dataScopeType :  DataScopeType.values()   ) {
            if(dataScopeType.getCode().equals(code)) {
                return dataScopeType.getInfo();
            }
        }
       throw new BusinessException(ErrorCodeEnum.DATA_SCOPE.setParam("code:"+code));
    }

    public static boolean contains(Byte code){
        if(code >=0 && code<=4){
            return true;
        }
        return false;
    }

    public Byte getCode() {
        return code;
    }

    public String getInfo() {
        return info;
    }
}
